class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable, :validatable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable

  # ====================================================================================
  # ATTRIBUTES - PLACE
  # ====================================================================================


  # ====================================================================================
  # ASSOCIATIONS 
  # ====================================================================================

  
  has_many :products
  
  has_one :avatar, as: :photoable

  # ====================================================================================
  # VALIDATES 
  # ====================================================================================


  # ====================================================================================
  # STATIC 
  # ====================================================================================

  # STATUS     = { pending: 0, active: 1, inactive: 2, deleted: 3 }
  USER_ROLE = {user: 0, admin: 1}

  # ====================================================================================
  # SCOPES 
  # ====================================================================================
  # scope :pending , -> { where(m_status: STATUS[:pending])}
  # scope :active  , -> { where(m_status: STATUS[:active])}
  # scope :inactive, -> { where(m_status: STATUS[:inactive])}
  # scope :deleted , -> { where(m_status: STATUS[:deleted])}

  # ====================================================================================
  # INSTANCE - GET - FUNTIONS
  # ====================================================================================


  # ====================================================================================
  # INSTANCE - TODO - FUNTIONS
  # ====================================================================================


  # ====================================================================================
  # INSTANCE - FIND - FUNTIONS
  # ====================================================================================


  # ====================================================================================
  # INSTANCE - CHECK - FUNTIONS
  # ====================================================================================

  def is_admin?
    self.m_user_role == USER_ROLE[:admin]
  end

  # ====================================================================================
  # CLASS - GET - FUNTIONS
  # ====================================================================================

  def self.newest limit
    self.order(created_at: :desc).limit(limit)
  end

  # ====================================================================================
  # CLASS - TODO - FUNTIONS
  # ====================================================================================


  # ====================================================================================
  # CLASS - FIND - FUNTIONS
  # ====================================================================================


  # ====================================================================================
  # CLASS - CHECK - FUNTIONS
  # ====================================================================================


  # ====================================================================================
  # CALLBACK - FUNTIONS
  # ====================================================================================


  # ====================================================================================
  # PROTECTED - FUNTIONS
  # ====================================================================================


  # ====================================================================================
  # PRIVATE - FUCTIONS
  # ====================================================================================

end
